<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Record extends Model
{
    use HasFactory;

    protected $guarded = [];


    protected $appends = ['typestatus', 'username'];

    protected $transtype = ['donate' => '转移', 'writeOff' => '兑换'];

    protected function getUsernameAttribute()
    {
        return $this->user->name;
    }

    protected function getTypestatusAttribute()
    {
        return $this->transtype[$this->type];
    }

    public function voucher()
    {
        return $this->belongsTo(Voucher::class, 'voucher_id', 'uuid');
    }

    public function user()
    {
        return $this->belongsTo(User::class);
    }
}
